#include"Teacher.h"
#include<stdio.h>
#include<string.h>



void InitTeacher(Teach *t, int id,const char *name)
{
    t->id = id;
    strcpy(t->Name,name);
    t->size = 0;
}

void AddStudent(Teach *t, int StuId, const char *name)
{
    if(t->size>=10)
    {
        printf("已经达到上限了！\n");
    }
    
    t-> s[t->size].id = StuId;
    strcpy(t->s[t->size].Name,name);
    t->size++;
}

void RemoveByIndex(Teach *t,int index)
{
    if(index < 0 ||index >= t->size)
    {
    printf("非法位置的删除！\n");
    return;
    }
   
    for (int i = index; i < t->size; i++)
    {
        t->s[i] = t->s[i+1];
    }
    
   
}

void RemoveStudent(Teach *t, void* data, bool IsEqual(void*,void*))
{
    for( int i = 0 ; i < t->size ; i++ )
    {
        if (IsEqual(&t->s[i],data)) // 回调函数 ：函数以参数形式传递给另一个函数：提高代码的可扩展性
        {
            RemoveByIndex(t,i);
            t->size--;
            i--;
        }       
    }    
}

void RemoveStuByName(Teach *t, const char*name)
{
    for(int i=0;i<t->size;i++)
    {
        if (strcmp(t->s[i].Name,name) == 0)
        {
            RemoveByIndex(t,i);
            t->size--;
            i--;
        }       
    } 
}

void PrintTeacher(Teach *t)
{
    printf("老师%d %s\n",t->id,t->Name);

    printf("学生列表:\n");
    for(int i=0; i < t->size ; i++)
    {
        PrintStu(t->s+i);
    }

    
}

Stu *FindStudent(Teach *t, void *data, bool (*IsEqual)(void *, void *))
{
    for( int i = 0 ; i < t->size ; i++ )
    {
        if (IsEqual(&t->s[i],data)) // 回调函数 ：函数以参数形式传递给另一个函数：提高代码的可扩展性
        {
           return &t->s[i];
        }       
    } 
    return NULL;
}

void InitTeacher(Teach *t, int id, const char *name, int size)
{
    
}
